package com.dahua.service;

import android.app.DownloadManager;
import android.app.Service;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;

import com.dahua.receive.CompleteReceiver;


public class InstalllApkService extends Service {
	
	private CompleteReceiver receiver;
	
	@Override
	public IBinder onBind(Intent arg0) {
		return null;
	}

	@Override
	public void onCreate() {
		super.onCreate();
		receiver = new CompleteReceiver(this);
		registerReceiver();
	}
	
	
	
	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		// TODO Auto-generated method stub
		return super.onStartCommand(intent, flags, startId);
	}

	private void registerReceiver() {
		IntentFilter filter = new IntentFilter();
		filter.addAction(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
		registerReceiver(receiver, filter);
	}
	
	private void unregisterReceiver() {
		if (receiver != null) {
			unregisterReceiver(receiver);
			receiver = null;
		}
	}

	@Override
	public void onDestroy() {
		unregisterReceiver();
		super.onDestroy();
	}
	
}
